package com.un10.controller;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.un10.entity.Odersdentails;
import com.un10.entity.Orders;
import com.un10.entity.Proclass;
import com.un10.service.OrdersService;
import com.un10.service.ProclassService;
import com.un10.util.Result;

@Controller
public class OrdersContorller {
	@Autowired
	OrdersService ordersService;

//��ѯ
	@RequestMapping("/houtai/getorders")
	@ResponseBody
//��bug 
	public Object getorders(@RequestParam("page") int page, @RequestParam("limit") int limit,@RequestParam("orderStatus") String orderStatus) {

		List<Orders> oders = ordersService.findAllOrders((page - 1) * limit, limit,orderStatus);

		if (orderStatus == null || orderStatus == "") {
			orderStatus = null;
		}
		int count = ordersService.getCount();
		com.un10.util.Result res = new com.un10.util.Result(0, "", count, oders);
		return res;
	}

	@RequestMapping("/houtai/deleteOrders")

	@ResponseBody
	public Object deleteOrders(@RequestParam("orderID") Integer orderID) {
		int i = ordersService.findOrdersDelete(orderID);
		Result res = new Result(0, "", i, true);
		return res;
	}
	
	@RequestMapping("/houtai/updateOrders")
	@ResponseBody
	public Object updateOrders(@RequestParam Map<String, Object> map) {
	
		int i = ordersService.findOrdersUpdate(map);
		Result res = new Result(0, "", i, true);
		return res;
	}
	
//	订单详情
	@RequestMapping("/houtai/OdersdetailsList")
	@ResponseBody
	public Object OdersdetailsList(@RequestParam("page") int page,@RequestParam("limit") int limit,@RequestParam("orderID") Integer orderID) {
	
		List<Odersdentails> ordersdentails = ordersService.findgetOdersdetailsAll((page - 1) * limit, limit,orderID);

		if (orderID == null ) {
			orderID = null;
		}
		int count = ordersService.getCount();
		com.un10.util.Result res = new com.un10.util.Result(0, "", count, ordersdentails);
		return res;
	}
	
}
